﻿@model HZU.ZP.Domain.Model.Notice
@{
    Layout = "_AdminLayout";
}
<script src="https://unpkg.com/wangeditor/release/wangEditor.min.js"></script>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="form-group">
                <label for="exampleInputEmail1">标题</label>
                <input type="text" class="form-control" id="title" value="@Model.Title" />
            </div>
        </div>
    </div>
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="form-group">
                <label for="exampleInputEmail1">内容</label>
                <div id="div1">
                </div>
            </div>
        </div>
    </div>
    <div class="row clearfix">
        <div class="col-md-6 column">
            <div class="form-group">
                <a href="/Notice/NoticeList" class="form-control" style="width:50%;float:right;">取消</a>
            </div>
        </div>
        <div class="col-md-6 column">
            <div class="form-group">
                <button id="save" class="form-control" style="background-color: #79CDCD;width:50%;float:left;">保存</button>
            </div>
        </div>
    </div>
</div>



<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
    var E = window.wangEditor
    var editor = new E('#div1')
    var $text1 = $('#text1')
    editor.customConfig.customUploadImg = function (files, insert) {
        var date = new FormData();
        date.append("files", files[0]);
        $.ajax({
            type: "POST",
            url: "/Notice/UploadImg",
            data: date,
            contentType: false,
            processData: false,
            success: function (result) {
                insert(result.data);// insert 是获取图片 url 后，插入到编辑器的方法
            }
        })
    };
    editor.create()
    editor.txt.html('@Html.Raw(Model.Content)')

    document.getElementById('save').addEventListener('click', function () {
        $.ajax({
            type: "POST",
            url: "/Notice/UpdateNotice",
            data: 'id=@Model.Id&title=' + $("#title").val() + "&content=" + editor.txt.html(),
            success: function (message) {
                if (message.returnCode == "001") {
                    alert("修改成功");
                    window.location.reload();
                }
            }
        })
    }, false)
</script>


